﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using HP.Cachalote.Services.Shared;

namespace HP.Cachalote.UnitTests.WPFTests
{
    [TestFixture]
    public class GeneralUtilitiesTest
    {
        [SetUp]
        public void Setup() { }

        #region Tests for GetDateOfSaturday
        [Test]
        public void GetDateOfSaturdayBySundayTest()
        {
            var currentDate = new DateTime(2012, 11, 4);    // Sunday
            var expected = new DateTime(2012, 11, 10);      // Saturday
            var actual = GeneralUtilities.GetDateOfSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfSaturdayByMondayTest()
        {
            var currentDate = new DateTime(2012, 11, 5);    // Monday
            var expected = new DateTime(2012, 11, 10);      // Saturday
            var actual = GeneralUtilities.GetDateOfSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfSaturdayByTuesdayTest()
        {
            var currentDate = new DateTime(2012, 11, 6);    // Sunday
            var expected = new DateTime(2012, 11, 10);      // Saturday
            var actual = GeneralUtilities.GetDateOfSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfSaturdayByWednesdayTest()
        {
            var currentDate = new DateTime(2012, 11, 7);    // Sunday
            var expected = new DateTime(2012, 11, 10);      // Saturday
            var actual = GeneralUtilities.GetDateOfSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfSaturdayByThursdayTest()
        {
            var currentDate = new DateTime(2012, 11, 8);    // Sunday
            var expected = new DateTime(2012, 11, 10);      // Saturday
            var actual = GeneralUtilities.GetDateOfSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfSaturdayByFridayTest()
        {
            var currentDate = new DateTime(2012, 11, 9);    // Sunday
            var expected = new DateTime(2012, 11, 10);      // Saturday
            var actual = GeneralUtilities.GetDateOfSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfSaturdayBySatursdayTest()
        {
            var currentDate = new DateTime(2012, 11, 10);    // Sunday
            var expected = new DateTime(2012, 11, 10);      // Saturday
            var actual = GeneralUtilities.GetDateOfSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }
        #endregion

        #region Tests for GetDateOfNextSaturday
        [Test]
        public void GetDateOfNextSaturdayBySundayTest()
        {
            var currentDate = new DateTime(2012, 11, 4);    // Sunday
            var expected = new DateTime(2012, 11, 17);      // Saturday
            var actual = GeneralUtilities.GetDateOfNextSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfNextSaturdayByMondayTest()
        {
            var currentDate = new DateTime(2012, 11, 5);    // Monday
            var expected = new DateTime(2012, 11, 17);      // Saturday
            var actual = GeneralUtilities.GetDateOfNextSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfNextSaturdayByTuesdayTest()
        {
            var currentDate = new DateTime(2012, 11, 6);    // Sunday
            var expected = new DateTime(2012, 11, 17);      // Saturday
            var actual = GeneralUtilities.GetDateOfNextSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfNextSaturdayByWednesdayTest()
        {
            var currentDate = new DateTime(2012, 11, 7);    // Sunday
            var expected = new DateTime(2012, 11, 17);      // Saturday
            var actual = GeneralUtilities.GetDateOfNextSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfNextSaturdayByThursdayTest()
        {
            var currentDate = new DateTime(2012, 11, 8);    // Sunday
            var expected = new DateTime(2012, 11, 17);      // Saturday
            var actual = GeneralUtilities.GetDateOfNextSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfNextSaturdayByFridayTest()
        {
            var currentDate = new DateTime(2012, 11, 9);    // Sunday
            var expected = new DateTime(2012, 11, 17);      // Saturday
            var actual = GeneralUtilities.GetDateOfNextSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void GetDateOfNextSaturdayBySatursdayTest()
        {
            var currentDate = new DateTime(2012, 11, 10);   // Sunday
            var expected = new DateTime(2012, 11, 17);      // Saturday
            var actual = GeneralUtilities.GetDateOfNextSaturday(currentDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }
        #endregion

        #region Tests for CheckIsSameYear
        [Test]
        public void CheckIsSameYearWithCorrectResultTest()
        {
            var dateA = new DateTime(2012, 11, 4);
            var dateB = new DateTime(2012, 11, 17);
            var expected = true;
            var actual = GeneralUtilities.CheckIsSameYear(dateA, dateB);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void CheckIsSameYearWithIncorrectYearTest()
        {
            var dateA = new DateTime(2012, 11, 4);
            var dateB = new DateTime(2013, 11, 17);
            var expected = false;
            var actual = GeneralUtilities.CheckIsSameYear(dateA, dateB);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }
        #endregion

        #region Tests for CheckIsSameYearAndMonth
        [Test]
        public void CheckIsSameYearAndMonthWithCorrectResultTest()
        {
            var dateA = new DateTime(2012, 11, 4);
            var dateB = new DateTime(2012, 11, 17);
            var expected = true;
            var actual = GeneralUtilities.CheckIsSameYearAndMonth(dateA, dateB);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void CheckIsSameYearAndMonthWithIncorrectYearTest()
        {
            var dateA = new DateTime(2012, 11, 4);
            var dateB = new DateTime(2013, 11, 17);
            var expected = false;
            var actual = GeneralUtilities.CheckIsSameYearAndMonth(dateA, dateB);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void CheckIsSameYearAndMonthWithIncorrectMonthTest()
        {
            var dateA = new DateTime(2012, 11, 4);
            var dateB = new DateTime(2012, 10, 17);
            var expected = false;
            var actual = GeneralUtilities.CheckIsSameYearAndMonth(dateA, dateB);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }
        #endregion

        #region Tests for CheckIsSameYearAndNextMonth
        [Test]
        public void CheckIsSameYearAndNextMonthWithCorrectResultTest()
        {
            var date = new DateTime(2012, 11, 4);
            var nextMonthDate = new DateTime(2012, 12, 17);
            var expected = true;
            var actual = GeneralUtilities.CheckIsSameYearAndNextMonth(date, nextMonthDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void CheckIsSameYearAndNextMonthWithIncorrectYearTest()
        {
            var date = new DateTime(2012, 11, 4);
            var nextMonthDate = new DateTime(2013, 12, 17);
            var expected = false;
            var actual = GeneralUtilities.CheckIsSameYearAndNextMonth(date, nextMonthDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }

        [Test]
        public void CheckIsSameYearAndNextMonthWithIncorrectMonthTest()
        {
            var date = new DateTime(2012, 11, 4);
            var nextMonthDate = new DateTime(2012, 10, 17);
            var expected = false;
            var actual = GeneralUtilities.CheckIsSameYearAndNextMonth(date, nextMonthDate);

            Assert.AreEqual(expected, actual, string.Format("Expected is {0}. Actual is {1}.", expected, actual));
        }
        #endregion
    }
}
